*******************************************************************************
* Load candidates data
*******************************************************************************

use dataset_candidates, clear

*******************************************************************************
* Do the regressions for the full sample
*******************************************************************************

eststo clear
eststo: reg ideology deputy, cl(district)
eststo: reg ideology deputy trumpvoteshare, cl(district)
eststo: areg ideology deputy cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology deputy trumpvoteshare cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"

*******************************************************************************
* Output
*******************************************************************************

label variable deputy "Experienced"
label variable trumpvoteshare "Trump Vote Share"

#delimit;

esttab
	using "_output/table3_a.tex"
	,
		replace
		booktabs
		cells(b(fmt(3)) se(par) p(par("[" "]")))
		drop(cycle*) 
		stats(
			N cyclefe statefe,
			label(
				"Observations"
				"State fixed effects"
				"Cycle fixed effects"
			)
			fmt(%20.0f %20.0f)
		)
		label
		collabels(none)	
		mlabels(none)
		width(\linewidth)
		alignment(l)
		gap
		;
		
#delimit cr

*******************************************************************************
* Do the regressions for the sample with partisanship
*******************************************************************************

keep if !mi(party)

eststo clear
eststo: reg ideology deputy, cl(district)
eststo: reg ideology party_2-party_3, cl(district)
eststo: reg ideology deputy party_2-party_3 trumpvoteshare, cl(district)
eststo: areg ideology deputy cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology party_2-party_3 cycle_*, ///
	cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology deputy party_2-party_3 cycle_* trumpvoteshare, ///
	cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
//eststo: areg ideology deputy party_2-party_4 trumpvoteshare cycle_*, ///
//	cl(district) a(state)
//estadd local cyclefe = "X"
//estadd local statefe = "X"

*******************************************************************************
* Output
*******************************************************************************

label variable party_2 "Independent"
label variable party_3 "Republican"

#delimit;

esttab
	using "_output/table3_b.tex"
	,
		replace
		booktabs
		cells(b(fmt(3)) se(par) p(par("[" "]")))
		drop(cycle*) 
		stats(
			N cyclefe statefe,
			label(
				"Observations"
				"State fixed effects"
				"Cycle fixed effects"
			)
			fmt(%20.0f %20.0f)
		)
		label
		collabels(none)	
		mlabels(none)
		width(\linewidth)
		alignment(l)
		gap
		;
		
#delimit cr

*******************************************************************************
* End
*******************************************************************************
